package com.aqiang.day0528_shop.main.presenter

import com.aqiang.day0528_shop.main.contract.StairContract
import com.aqiang.day0528_shop.main.entity.BaseEntity
import com.aqiang.day0528_shop.main.entity.GoodsTypeEntity
import com.aqiang.day0528_shop.main.entity.T
import com.aqiang.day0528_shop.main.model.StairModel
import com.aqiang.lib_core.common.SLog
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.runBlocking

class StairPresenter(v:StairContract.StairView) : StairContract.StairPresenter(v) {
    override fun T() {
        if(mView != null && mView.get() != null){
            val stair:Deferred<BaseEntity<List<GoodsTypeEntity>>> = mModel.T(mView.get()!!.secondId())
//            var list:MutableList<T> = mutableListOf()
//            runBlocking {
//                if(stair != null){
//                    for (item in stair.await().data){
//                        val t1 = T(item.category_id,item.category_name,item.id,item.parent_id)
//                        list.add(t1)
//                    }
//                }
//            }
            mView.get()!!.initT(stair)
//            return list
        }
    }

    override fun second() {
        if(mView != null && mView.get() != null){
            val stair = mModel.second(mView.get()!!.secondId())
            mView.get()!!.initsecond(stair)
        }
    }

    override fun stair() {
        if(mView != null && mView.get() != null){
            val stair = mModel.stair(mView.get()!!.stairId())
            mView.get()!!.initStair(stair)
        }
    }

    override fun initModel(): StairContract.StairModel {
       return StairModel()
    }
}